<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateLearnVideosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('learn_videos', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('名称');
            $table->string('thumb')->nullable()->comment('封面图');
            $table->decimal('original_price')->default(0)->index()->comment('原价格');
            $table->decimal('price')->default(0)->index()->comment('价格');
            $table->integer('view_count')->index()->default(0)->comment('观看次数');
            $table->integer('real_view_count')->index()->default(0)->comment('真实观看次数');
            $table->integer('buy_count')->index()->default(0)->comment('购买次数');
            $table->integer('real_buy_count')->index()->default(0)->comment('真实购买次数');
            $table->integer('learn_count')->index()->default(0)->comment('学习人数');
            $table->integer('real_learn_count')->index()->default(0)->comment('真实学习人数');
            $table->integer('chapter_count')->default(0)->index()->comment('章数');
            $table->integer('section_count')->default(0)->index()->comment('节数');
            $table->double('total_second')->default(0)->index()->comment('总秒数');
            $table->text('details')->nullable()->comment('详情');
            $table->tinyInteger('is_done')->default(0)->index()->comment('是否完结：0=否，1=是');
            $table->tinyInteger('is_active')->default(0)->index()->comment('是否上架：0=否，1=是');
            $table->tinyInteger('is_limited_free')->default(0)->index()->comment('是否限免：0=否，1=是');
            $table->dateTime('limited_free_end_at')->nullable()->comment('限免结束时间');
            $table->tinyInteger('effective_type')->default(4)->index()->comment('有效类型：1=天，2=日期，3=长期');
            $table->integer('effective_days')->nullable()->index()->comment('有效天数');
            $table->dateTime('effective_date')->nullable()->index()->comment('有效日期');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE learn_videos comment '学习视频'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('learn_videos');
    }
}
